package com.violet.controller.app;

import com.violet.domain.dto.app.AOrderDto;
import com.violet.domain.result.Result;
import com.violet.domain.result.ResultPage;
import com.violet.domain.search.MyPage;
import com.violet.domain.vo.app.AOrderVo;
import com.violet.service.app.AWaitPaidOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app/order/wait_paid")
@RequiredArgsConstructor
public class AWaitPaidOrderController {

    private final AWaitPaidOrderService service;

    // 分页获取待支付的订单
    @GetMapping
    public ResultPage<List<AOrderVo>> getWaitPayOrders(@ModelAttribute MyPage myPage) {
        return service.getWaitPayOrders(myPage);
    }

    // 创建一个待支付的订单
    @PostMapping
    public Result<String> createWaitPayOrder(@RequestBody AOrderDto dto) {
        service.createWaitPayOrder(dto);
        return Result.success();
    }

    // 取消一个待支付订单
    @DeleteMapping("/{id}")
    public Result<Boolean> cancelWaitPayOrder(@PathVariable String id) {
        return Result.success(service.cancelWaitPayOrder(id), "取消待支付订单");
    }

    // 付款一个待支付订单
    @PutMapping("/{id}")
    public Result<Boolean> payWaitPayOrder(@PathVariable String id) {
        return Result.success(service.payWaitPayOrder(id), "付款待支付订单");
    }

}
